home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE23 / CLINIC / APP1U.PAS < prev    next >
Pascal/Delphi Source File  |  1997-04-28  |  2KB  |  80 lines

  1. unit App1U;
  2.  
  3. interface
  4.  
  5. uses
  6.   WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls;
  8.  
  9. type
  10.   TControllerMainForm = class(TForm)
  11.     Button1: TButton;
  12.     Button2: TButton;
  13.     Button3: TButton;
  14.     procedure Button1Click(Sender: TObject);
  15.     procedure Button2Click(Sender: TObject);
  16.     procedure Button3Click(Sender: TObject);
  17.   private
  18.     { Private declarations }
  19.   public
  20.     { Public declarations }
  21.   end;
  22.  
  23. var
  24.   ControllerMainForm: TControllerMainForm;
  25.  
  26. implementation
  27.  
  28. {$R *.DFM}
  29.  
  30. procedure ActivateWindow(Caption, ClassName: PChar);
  31. var
  32.   FormWnd, AppWnd: HWnd;
  33. begin
  34.   FormWnd := FindWindow(ClassName, Caption);
  35.   if FormWnd = 0 then
  36.     raise Exception.Create('Cannot find window');
  37. {$ifdef Win32}
  38.   { Having found the form, now find the Application window }
  39.   { Can't reliably use GetParent, so... }
  40.   AppWnd := GetWindowLong(FormWnd, gwl_HWndParent);
  41.   { Tell the Delphi Application window to pop up in case it }
  42.   { is minimised. Bear in mind that FindWindow only works on }
  43.   { top-level windows, not child windows. Delphi forms are }
  44.   { top-level popup windows which have parents, so the following }
  45.   { check should only try and restore a parent window if it }
  46.   { is a Delphi app }
  47.   if (AppWnd <> HWnd_Desktop) and IsIconic(AppWnd) then
  48.     SendMessage(AppWnd, wm_SysCommand, sc_Restore, 0);
  49.   { Tell the form window to pop up if it is minimised }
  50.   if IsIconic(FormWnd) then
  51.     SendMessage(FormWnd, wm_SysCommand, sc_Restore, 0);
  52.   { Make the target form be in front and active }
  53.   SetForegroundWindow(FormWnd);
  54. {$else}
  55.   AppWnd := GetWindowWord(FormWnd, gww_HWndParent);
  56.   if (AppWnd <> HWnd_Desktop) and IsIconic(AppWnd) then
  57.     SendMessage(AppWnd, wm_SysCommand, sc_Restore, 0);
  58.   if IsIconic(FormWnd) then
  59.     SendMessage(FormWnd, wm_SysCommand, sc_Restore, 0);
  60.   BringWindowToTop(FormWnd);
  61. {$endif}
  62. end;
  63.  
  64. procedure TControllerMainForm.Button1Click(Sender: TObject);
  65. begin
  66.   ActivateWindow('MainForm', 'TMainForm')
  67. end;
  68.  
  69. procedure TControllerMainForm.Button2Click(Sender: TObject);
  70. begin
  71.   ActivateWindow('SecondaryForm', 'TSecondaryForm')
  72. end;
  73.  
  74. procedure TControllerMainForm.Button3Click(Sender: TObject);
  75. begin
  76.   ActivateWindow(nil, 'XLMAIN')
  77. end;
  78.  
  79. end.
  80.